import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.math.BigInteger;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JLabel;


public class GUImain extends JFrame {

	private JPanel contentPane;
	private JTextField txtLiczbaWtkw;
	private JTextField txtIloLiczb;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GUImain frame = new GUImain();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public GUImain() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		final JTextPane textPane = new JTextPane();
		textPane.setBounds(106, 29, 131, 51);
		contentPane.add(textPane);
		
		
		
		txtLiczbaWtkw = new JTextField();
		txtLiczbaWtkw.setText("4");
		txtLiczbaWtkw.setBounds(10, 29, 86, 20);
		contentPane.add(txtLiczbaWtkw);
		txtLiczbaWtkw.setColumns(10);
		
		txtIloLiczb = new JTextField();
		txtIloLiczb.setText("1000");
		txtIloLiczb.setBounds(10, 82, 86, 20);
		contentPane.add(txtIloLiczb);
		txtIloLiczb.setColumns(10);
		
		JButton btnStart = new JButton("START");
		btnStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int lwat;
				int lliczb;
				lwat = Integer.parseInt(txtLiczbaWtkw.getText());
				lliczb = Integer.parseInt(txtIloLiczb.getText());
				long start=System.currentTimeMillis();
						
				 try {
                     Management main = new Management(512,lwat);
                     
                     BigInteger a= new BigInteger(Integer.toString(lliczb));
                      main.calculatePrimeNumbers(a);
                      //main.print();
                   System.out.println("zakonczono obliczenia");
                   main=null;         
				 } 
              catch (Exception g) {
                      // TODO Auto-generated catch block
                      System.out.println(g.getMessage());
                      g.printStackTrace();
              }
				 long stop=System.currentTimeMillis();
				 System.out.println("Czas wykonania:"+(stop-start));
				 long wynik= stop-start;
				 String wynikms= Long.toString(wynik);
				 textPane.setText(wynikms+"  ms");
			}
		});
		btnStart.setBounds(10, 227, 89, 23);
		contentPane.add(btnStart);
		
		JLabel lblLiczbaWtkw = new JLabel("Liczba w\u0105tk\u00F3w");
		lblLiczbaWtkw.setBounds(10, 11, 86, 14);
		contentPane.add(lblLiczbaWtkw);
		
		JLabel lblLiczbaLiczb = new JLabel("Liczba liczb");
		lblLiczbaLiczb.setBounds(10, 60, 86, 14);
		contentPane.add(lblLiczbaLiczb);
		
		
		
		
		
	}
}
